package androidx.savedstate;

import android.annotation.SuppressLint;
import android.os.Bundle;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Iterator;
import o.kp.e;
import o.ks;
import o.kv;
import o.mr;
import o.my;

@SuppressLint({"RestrictedApi"})
public final class Recreator implements ks {
    private final my ॱ;

    public Recreator(my myVar) {
        this.ॱ = myVar;
    }

    public void ˊ(kv kvVar, e eVar) {
        if (eVar != e.ON_CREATE) {
            throw new AssertionError("Next event must be ON_CREATE");
        }
        kvVar.ac_().ˋ(this);
        Bundle ˋ = this.ॱ.V_().ˋ("androidx.savedstate.Restarter");
        if (ˋ != null) {
            ArrayList stringArrayList = ˋ.getStringArrayList("classes_to_restore");
            if (stringArrayList == null) {
                throw new IllegalStateException("Bundle with restored state for the component \"androidx.savedstate.Restarter\" must contain list of strings by the key \"classes_to_restore\"");
            }
            Iterator it = stringArrayList.iterator();
            while (it.hasNext()) {
                ˎ((String) it.next());
            }
        }
    }

    private void ˎ(String str) {
        try {
            Class asSubclass = Class.forName(str, false, Recreator.class.getClassLoader()).asSubclass(mr.e.class);
            try {
                Constructor declaredConstructor = asSubclass.getDeclaredConstructor(new Class[0]);
                declaredConstructor.setAccessible(true);
                try {
                    ((mr.e) declaredConstructor.newInstance(new Object[0])).ˎ(this.ॱ);
                } catch (Throwable e) {
                    throw new RuntimeException("Failed to instantiate " + str, e);
                }
            } catch (Throwable e2) {
                throw new IllegalStateException("Class" + asSubclass.getSimpleName() + " must have default constructor in order to be automatically recreated", e2);
            }
        } catch (Throwable e22) {
            throw new RuntimeException("Class " + str + " wasn't found", e22);
        }
    }
}
